package com.a3dweijing.wetouch2.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.a3dweijing.wetouch2.Common.CallBack;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.bean.ReporterListMsg;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Yxd on 2018/3/22.
 */

public class ReportListAdapter extends RecyclerView.Adapter<ReportListAdapter.MyViewHolder> {
    List<ReporterListMsg.ListBean> beans;
    CallBack callBack;

    public ReportListAdapter(List<ReporterListMsg.ListBean> beans, CallBack callBack) {
        this.beans = beans;
        this.callBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_health_report_list,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年 MM月 dd日");
        holder.time.setText(sdf.format(new Date((beans.get(position).getCreate_time())*1000)));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (callBack!=null ){
                    callBack.doNext(position,beans.get(position));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView time;
        public MyViewHolder(View itemView) {
            super(itemView);
            time=itemView.findViewById(R.id.report_item_time);
        }
    }
}
